<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){   //进入列表页
       // $this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎大家都使用 <b>ThinkPHP</b>！</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
   $neirong=M('wenzhang');
   $meiye=2;
   $xinxi=$neirong->limit("0,$meiye")->select();
  $juti=$neirong->select();
	  
	 $shuliang=count($juti);
	
	$zongyemian=ceil($shuliang/$meiye);

   $this->assign('xinxi',$xinxi)->assign('zongyemian',$zongyemian)->assign('page','1')->assign("qufen",'1');

   $this->display();
	}
	public function xiangqing(){  //进入详情页
		if(empty($_GET['id']))
		{
			$this->redirect('/');
		}
		else
		{
			 $id=$_GET['id'];
		 $neirong=M('wenzhang');
		 $juti=$neirong->where("id=$id")->getField('neirong');
		$this->assign('neirong',$juti);
		
		$this->display();
		}
	     
	}
	public function tiaozhuan()
	{
		$page=$_GET['page'];
		 
		
	
	     $neirong=M('wenzhang');
		 $juti=$neirong->select();
	       $meiye=2;
		   $shuliang=count($juti);
		   $zongyemian=ceil($shuliang/$meiye);
			
        if(empty($page)||$page<=0)
		{
			$page=1;//跳转第一页
		}	
		
		  $page=(int)$page;
          $pagenum=($page-1)*$meiye;
		  $xinxi=$neirong->limit("$pagenum,$meiye")->select();
		  
      $this->assign('xinxi',$xinxi)->assign('page',$page)->assign('zongyemian',$zongyemian)->assign('qufen','1');
	 
      $this->display('index/index');	  
		  
	}
	public function guanjianzi()   //关键字查询方法
	{
		$i=0;
		$chaxun="";               //此变量用来存放符合关键字的文章id
		$guanjianzi=$_GET['guanjianzi'];
		$neirong=M('wenzhang');
		$list=$neirong->select();
		foreach($list as $value)
		{
			
			   
                   $zifuchuan= $value['biaoti'];  
              $jieguo=strstr($zifuchuan,$guanjianzi);
			  
              if($jieguo==true)
              {
				  $i=++$i;
				  if($i==1)
				  {
					   $chaxun=$value['id']; 
				  }
				  else
				  {
					   $chaxun.=",".$value['id']; 
				  }
				
			  }				  
             			  
		}
	    $juti=$neirong->where("id in (".$chaxun.")")->select();
		
		$meiye=2;
		   $shuliang=count($juti);
		   $zongyemian=ceil($shuliang/$meiye);
			
       /* if(empty($page)||$page<=0)
		{
			$page=1;//跳转第一页
		}	
		
		  $page=(int)$page;
          $pagenum=($page-1)*$meiye;*/
		  $xinxi=$neirong->where("id in (".$chaxun.")")->limit("0,$meiye")->select();
		
		
		$this->assign('xinxi',$xinxi)->assign('page',1)->assign('zongyemian',$zongyemian)->assign('qufen','2')->assign('guanjianzi',$guanjianzi);
	 
      $this->display('index/index');	  
	}
	public function guanjiantiaozhuan()
	{
		$page=$_GET['page'];
	    $guanjianzi=$_GET['guanjianzi'];
		$i=0;
		$chaxun="";               //此变量用来存放符合关键字的文章id
		$meiye=2;
	
		$neirong=M('wenzhang');
		$list=$neirong->select();
		foreach($list as $value)
		{
			
			   
                   $zifuchuan= $value['biaoti'];  
              $jieguo=strstr($zifuchuan,$guanjianzi);
			  
              if($jieguo==true)
              {
				  $i=++$i;
				  if($i==1)
				  {
					   $chaxun=$value['id']; 
				  }
				  else
				  {
					   $chaxun.=",".$value['id']; 
				  }
				
			  }				  
             			  
		}
	    $juti=$neirong->where("id in (".$chaxun.")")->select();
		
		echo $juti;
		   $shuliang=count($juti);
		   $zongyemian=ceil($shuliang/$meiye);
			
        if(empty($page)||$page<=0)
		{
			$page=1;//跳转第一页
		}	
		
		  
		  $page=(int)$page;
          $pagenum=($page-1)*$meiye;
		  $xinxi=$neirong->where("id in (".$chaxun.")")->limit("$pagenum,$meiye")->select();
		
		$this->assign('xinxi',$xinxi)->assign('page',$page)->assign('zongyemian',$zongyemian)->assign('qufen','2')->assign('guanjianzi',$guanjianzi);
	
	 
      $this->display('index/index');	  
		
	}
		
		
	

		  
	
}